﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;

namespace AndersLiu.EmailQueue.Service
{
	public partial class EmailQueueService : ServiceBase
	{
		public EmailQueueService()
		{
			InitializeComponent();
		}

		protected override void OnStart(string[] args)
		{
			StartThreads();
			base.OnStart(args);
		}

		protected override void OnStop()
		{
			StopThreads();
			base.OnStop();
		}

		protected override void OnContinue()
		{
			StartThreads();
			base.OnContinue();
		}

		protected override void OnPause()
		{
			StopThreads();
			base.OnPause();
		}

		protected override void OnShutdown()
		{
			StopThreads();
			base.OnShutdown();
		}

		/// <summary>
		/// 标志。标志着是否正在退出。
		/// </summary>
		bool _isStopping = false;

		/// <summary>
		/// 用于保存所有发送线程。
		/// </summary>
		List<Thread> _threads = new List<Thread>();

		/// <summary>
		/// 启动所有发送线程。
		/// </summary>
		private void StartThreads()
		{
		}

		/// <summary>
		/// 将_isStopping设置为true，然后等待所有发送线程完成发送。
		/// </summary>
		private void StopThreads()
		{
			_isStopping = true;
			foreach (var t in _threads)
				t.Join();
		}

		private void EmailSendingThread()
		{
		}
	}
}
